package com.feng.behavior
{
	import com.feng.ControllerCenter;
	import com.feng.debug.logger;
	import com.feng.model.Behavior;

	import flash.utils.Dictionary;

	/**
	 * 行为控制中心
	 * @author 风之守望者
	 * 2013-3-28
	 */
	public class BehaviorControler
	{
		/**
		 * 初始化行为表
		 */
		private function initBehaviorControler():void
		{
			//初始化 攻击型 行为表
			behaviorMap[BehaviorType.KILL_STEAL] = attackBehavior.kill_steal;
			behaviorMap[BehaviorType.BURANG_RENTOU] = attackBehavior.burang_rentou;

			behaviorMap[BehaviorType.ATTACT_THREE_STRATEGY] = attackBehavior.attact_three_strategy;
			behaviorMap[BehaviorType.ATTACT_FOUR_STRATEGY] = attackBehavior.attact_four_strategy;
			behaviorMap[BehaviorType.ATTACT_FIVE_STRATEGY] = attackBehavior.attact_five_strategy;
			behaviorMap[BehaviorType.ATTACT_SIX_STRATEGY] = attackBehavior.attact_six_strategy;


			//初始化 防御型 行为表
			behaviorMap[BehaviorType.KILL_STEAL_DEFENSE] = defenseBehavior.kill_steal_defense;
			
			behaviorMap[BehaviorType.CHALLENGE_MODE_DEFENSE] = defenseBehavior.challenge_mode_defense;
			behaviorMap[BehaviorType.THREE_MODE_DEFENSE] = defenseBehavior.three_mode_defense;
			behaviorMap[BehaviorType.FOUR_MODE_DEFENSE] = defenseBehavior.four_mode_defense;
			behaviorMap[BehaviorType.FIVE_MODE_DEFENSE] = defenseBehavior.five_mode_defense;
			behaviorMap[BehaviorType.SIX_MODE_DEFENSE] = defenseBehavior.six_mode_defense;
		}

		/**
		 * 思考攻击
		 */
		public function ponderAttack():void
		{
			logger(JSON.stringify(attackSetting));
			logger("思考攻击");
			for each (var behavior:Behavior in attackSetting)
			{
				logger("处理【" + JSON.stringify(behavior) + "】行为");
				if (behavior && behaviorMap[behavior.behaviorType])
				{
					behaviorMap[behavior.behaviorType](behavior.priority);
				}
				else
				{
					logger("出错了！没有定义【" + JSON.stringify(behavior) + "】行为");
				}
			}
		}

		/**
		 * 思考防御
		 */
		public function ponderDefense():void
		{
			logger(JSON.stringify(defenseSetting));
			logger("思考防御");
			for each (var behavior:Behavior in defenseSetting)
			{
				logger("处理【" + JSON.stringify(behavior) + "】行为");
				if (behavior && behaviorMap[behavior.behaviorType])
				{
					behaviorMap[behavior.behaviorType](behavior.priority);
				}
				else
				{
					logger("出错了！没有定义【" + JSON.stringify(behavior) + "】行为");
				}
			}
		}

		/*************************************************************/

		/**
		 * 行为字典
		 */
		private var behaviorMap:Dictionary = new Dictionary();

		/**
		 * 攻击型行为配置
		 */
		public var attackSetting:Vector.<Behavior>;

		/**
		 * 防御型行为配置
		 */
		public var defenseSetting:Vector.<Behavior>;

		private var controllerCenter:ControllerCenter;

		public function BehaviorControler(controllerCenter:ControllerCenter)
		{
			this.controllerCenter = controllerCenter;

			initBehaviorControler();
		}

		private function get defenseBehavior():DefenseBehavior
		{
			return controllerCenter.defenseBehavior;
		}

		private function get attackBehavior():AttackBehavior
		{
			return controllerCenter.attackBehavior;
		}

	}
}
